#include "eventqueue.h"

namespace Lab1
{

    void EventQueue::push( const std::shared_ptr<const Event> & event )
    {
        std::unique_lock < std::mutex > locker( mutex );
        queue.push( event );
        condition.notify_one();
    }

    std::shared_ptr < const Event > EventQueue::pop( const std::chrono::milliseconds & duration )
    {
        std::shared_ptr < const Event > result = 0;
        std::unique_lock < std::mutex > locker( mutex );
        condition.wait_for( locker, duration, [this]() -> bool{ return !queue.empty(); } );
        if( !queue.empty() )
        {
            result = queue.front();
            queue.pop();
        }
        return result;
    }
}

